<?php
/**
 * Created by PhpStorm.
 * User: g
 * Date: 2018/2/9
 * Time: 10:58
 */

namespace app\index\controller;


class Grzx extends Common
{
    //个人设置
    public function index(){
        $mttx = db('cg_grsz')->where('eid',session('employee_id'))->value('mttx');
        $this->assign('mttx',$mttx);
        $xdb = db('cg_grsz')->where('eid',session('employee_id'))->value('xdb');
        $this->assign('xdb',$xdb);
        return $this->fetch();
    }
    //保存个人设置
    public function add(){
        $mttx = $this->request->post('mttx');
        $xdb = $this->request->post('xdb');

        $count = db('cg_grsz')->where('eid',session('employee_id'))->count();
        $data = [];
        if($mttx){
            $data['mttx'] = $mttx;
        }
        if($xdb){
            $data['xdb'] = $xdb;
        }
        if($count){
            $bool = db('cg_grsz')->where('eid',session('employee_id'))->update($data);
        }else{
            $data['eid'] = session('employee_id');
            $bool = db('cg_grsz')->insert($data);
        }
        if(false !== $bool)
            echo json_encode(['success'=>true,'msg'=>'ok']);
        else
            echo json_encode(['success'=>false,'msg'=>'error']);
    }
}